package cn.yunhe.servlet;

import cn.yunhe.entity.User;
import cn.yunhe.service.UserService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
@WebServlet("/AddUserServlet")
public class AddUserServlet extends HttpServlet {

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String name = request.getParameter("username");
        String uname = request.getParameter("userusername");
        String pwd = request.getParameter("userpwd");
        String address = request.getParameter("useraddress");
        String email = request.getParameter("useremail");
        int flag = Integer.parseInt(request.getParameter("userflag"));

        User user = new User(name, uname, pwd, address, email, flag);
        UserService userService = new UserService();
        boolean fa = userService.register(user);
        if (fa) {//注册成功
            response.sendRedirect("UserByPageServlet");
        } else {//注册失败
            response.sendRedirect("manage/user-add.jsp");
        }


       // request.getRequestDispatcher("login.jsp").forward(request, response);


    }

}
